package com.github.tvbox.osc.ui.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.github.tvbox.osc.R;
import com.github.tvbox.osc.picasso.RoundTransformation;
import com.github.tvbox.osc.util.DefaultConfig;
import com.github.tvbox.osc.util.MD5;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;

import io.github.source.media.bean.MediaBean;
import me.jessyan.autosize.utils.AutoSizeUtils;

/**
 * 首頁熱播媒體
 */
public class HomeHotVodAdapter extends BaseQuickAdapter<MediaBean, BaseViewHolder> {
    public boolean hotVodDelete = false;

    public HomeHotVodAdapter() {
        super(R.layout.item_user_hot_vod, null);
    }

    @Override
    protected void convert(BaseViewHolder helper, MediaBean item) {
        // TODO : Add Delete Mode
        View tvDel = helper.getView(R.id.delFrameLayout);
        if (hotVodDelete) {
            tvDel.setVisibility(View.VISIBLE);
        } else {
            tvDel.setVisibility(View.GONE);
        }
        // check if set as last watched

        TextView tvRate = helper.getView(R.id.tvNote);
        if (item.getVodRemarks() == null || item.getVodRemarks().isEmpty()) {
            tvRate.setVisibility(View.GONE);
        } else {
            tvRate.setText(item.getVodRemarks());
            tvRate.setVisibility(View.VISIBLE);
        }
        helper.setText(R.id.tvName, item.getVodName());
        ImageView ivThumb = helper.getView(R.id.ivThumb);
        //由于部分电视机使用glide报错
        if (!TextUtils.isEmpty(item.getVodPic())) {
            Picasso.get()
                    .load(DefaultConfig.checkReplaceProxy(item.getVodPic()))
                    .transform(new RoundTransformation(MD5.string2MD5(item.getVodPic() + "position=" + helper.getLayoutPosition()))
                            .centerCorp(true)
                            .override(AutoSizeUtils.mm2px(mContext, 300), AutoSizeUtils.mm2px(mContext, 400))
                            .roundRadius(AutoSizeUtils.mm2px(mContext, 10), RoundTransformation.RoundType.ALL))
                    .placeholder(R.drawable.img_loading_placeholder)
                    .error(R.drawable.img_loading_placeholder)
                    .into(ivThumb);
        } else {
            ivThumb.setImageResource(R.drawable.img_loading_placeholder);
        }
    }
}